package com.factory;

import com.utils.SpringBeanUtil;
import com.zbkj.crmeb.plat.by.dto.Shipping;
import com.zbkj.crmeb.store.service.CommonStoreOrderService;
import com.zbkj.crmeb.store.service.impl.EasyRadiumOrderServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author: wsl
 * @date: 2024/3/17 0017 21:04
 * @ClassName: PushWarehouseFactory
 */
@Component
public class PushWarehouseFactory {

    @Value("${ym.push.warehouse.supplierIds}")
    private List<Integer> ymSupplierIds;

    @Value("${yw.push.warehouse.supplierIds}")
    private List<Integer> ywSupplierIds;

    @Value("${my.push.warehouse.supplierIds}")
    private List<Integer> mySupplierIds;

    @Value("${common.push.warehouse.supplierIds}")
    private List<Integer> commonSupplierIds;

    @Value("${wenLian.push.warehouse.supplierIds}")
    private List<Integer> wenLianSupplierIds;

    private static List<Integer> easySupplierIds;

    static{
        easySupplierIds = new ArrayList<>();
        easySupplierIds.add(244);
        easySupplierIds.add(275);
    }

    private static final Map<Integer, CommonStoreOrderService> CACHE_MAP = new HashMap<>();

    static class innerClass {
        private static final PushWarehouseFactory INSTANCE = new PushWarehouseFactory();
    }

    private PushWarehouseFactory() {
    }

    public static PushWarehouseFactory getInstance(){
        return innerClass.INSTANCE;
    }

    public CommonStoreOrderService getServiceInstance(Integer supplierId,String type){
        if (Objects.equals(type,"9610")){
            return SpringBeanUtil.getBean("directStoreOrderServiceImpl",CommonStoreOrderService.class);
        }
        if (null == supplierId){
            return SpringBeanUtil.getBean("commonStoreOrderServiceImpl",CommonStoreOrderService.class);
        }
        if (ymSupplierIds.contains(supplierId)){
            return SpringBeanUtil.getBean("ymStoreOrderServiceImpl",CommonStoreOrderService.class);
        }else if (ywSupplierIds.contains(supplierId)){
            return SpringBeanUtil.getBean("commonStoreOrderServiceImpl",CommonStoreOrderService.class);
        }else if(easySupplierIds.contains(supplierId)){
            return SpringBeanUtil.getBean("easyRadiumOrderServiceImpl", EasyRadiumOrderServiceImpl.class);
        }else if (mySupplierIds.contains(supplierId)){
            return SpringBeanUtil.getBean("myStoreOrderServiceImpl", CommonStoreOrderService.class);
        }else if (wenLianSupplierIds.contains(supplierId)){
            return SpringBeanUtil.getBean("wenLianStoreOrderServiceImpl",CommonStoreOrderService.class);
        }else {
            return SpringBeanUtil.getBean("commonStoreOrderServiceImpl",CommonStoreOrderService.class);
        }
    }
    public CommonStoreOrderService getServiceInstance(String warehouseName){
        CommonStoreOrderService commonStoreOrderService = null;
        if (StringUtils.isNotBlank(warehouseName)){
            commonStoreOrderService = SpringBeanUtil.getBean(warehouseName,CommonStoreOrderService.class);
        }
        if (null != commonStoreOrderService){
            return commonStoreOrderService;
        }
        if (Objects.equals(warehouseName,"directStoreOrderServiceImpl")){
            return SpringBeanUtil.getBean("directStoreOrderServiceImpl",CommonStoreOrderService.class);
        }else if (Objects.equals(warehouseName,"ymStoreOrderServiceImpl")){
            return SpringBeanUtil.getBean("ymStoreOrderServiceImpl",CommonStoreOrderService.class);
        }else if (Objects.equals(warehouseName,"commonStoreOrderServiceImpl")){
            return SpringBeanUtil.getBean("commonStoreOrderServiceImpl",CommonStoreOrderService.class);
        }else if(Objects.equals(warehouseName,"easyRadiumOrderServiceImpl")){
            return SpringBeanUtil.getBean("easyRadiumOrderServiceImpl", EasyRadiumOrderServiceImpl.class);
        }else if (Objects.equals(warehouseName,"myStoreOrderServiceImpl")){
            return SpringBeanUtil.getBean("myStoreOrderServiceImpl", CommonStoreOrderService.class);
        }else if (Objects.equals(warehouseName,"wenLianStoreOrderServiceImpl")){
            return SpringBeanUtil.getBean("wenLianStoreOrderServiceImpl",CommonStoreOrderService.class);
        }else if (Objects.equals(warehouseName,"ysyStoreOrderServiceImpl")){
            return SpringBeanUtil.getBean("ysyStoreOrderServiceImpl",CommonStoreOrderService.class);
        }else {
            return SpringBeanUtil.getBean("commonStoreOrderServiceImpl",CommonStoreOrderService.class);
        }
    }

    public boolean isYm(Integer supplierId){
        return ymSupplierIds.contains(supplierId);
    }

    public boolean isYw(Integer supplierId){
        return ywSupplierIds.contains(supplierId);
    }

    public boolean isCommon(Integer supplierId){
        return commonSupplierIds.contains(supplierId);
    }


    public Shipping getWarehouseInfo(Integer supplierId){
        Shipping shipping = new Shipping();
        shipping.setShippingLocation("中国");
        shipping.setWarehouseId("BSC"+supplierId);
        shipping.setWarehouseName("保税仓"+supplierId);
        return shipping;
//        if (isYm(supplierId)){
//            shipping.setWarehouseId("YMWZBSC");
//            shipping.setWarehouseName("有米温州保税仓");
//            return shipping;
//        }else if (isYw(supplierId)){
//            shipping.setWarehouseId("YWBSC");
//            shipping.setWarehouseName("义乌保税仓");
//            return shipping;
//        }else {
//            shipping.setWarehouseId("WZBSC");
//            shipping.setWarehouseName("温州保税仓");
//            return shipping;
//        }
    }

    public String getClearanceCode(Integer supplierId){
        if (isYm(supplierId)){
            return "YMWZZB";
        }else if (isYw(supplierId)){
            return "YWZB";
        }else {
            return "WZZB";
        }
    }

    public boolean isWenLian(Integer supplierId){
        return wenLianSupplierIds.contains(supplierId);
    }

    public String getCustomsRecordCode(Integer supplierId){
        if (null == supplierId){
            return "3303960EZ4";
        }
        // wenlian
        if (isWenLian(supplierId)){
            return "3303969A2C";
        }
        // suyun
        return "3303960EZ4";
    }




}
